home *** CD-ROM | disk | FTP | other *** search
/ 1,000+ Great Games / 1_1000 Games.iso / DOSGAMES / BOGGLE.ZIP / SOURCE.ZIP / LASTSQ.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-03  |  2.7 KB  |  83 lines

  1. /*****************************************************************************
  2. * Program:  LASTSQ.CPP
  3. *
  4. * This class is used to determine whether a newly selected
  5. * square is adjacent to the last selected square.  It does this
  6. * by comparing the row and column number of the new one against
  7. * the old.  Legal values are as follows (assume values are >0):
  8. *
  9. *       (row, col-1)  (row, col-1)
  10. *       (row+1, col)  (row+1, col+1)  (row+1, col-1)
  11. *       (row-1, col)  (row-1, col+1)  (row-1, col-1)
  12. *
  13. ******************************************************************/
  14. #include "lastsq.hpp"
  15.  
  16. /*****************************************************************************
  17. * Function: LastSquare
  18. * Parms:    none
  19. * Purpose:  constructor - will set the last square values to zero
  20. * Returns:  Nothing
  21. *****************************************************************************/
  22. LastSquare::LastSquare()
  23. {
  24.    reSetSquare ();
  25. }
  26.  
  27.  
  28. /*****************************************************************************
  29. * Function: isValidSquare
  30. * Parms:    row and column of square to check
  31. * Purpose:  checks for adjacency of the the new square against values
  32. *           stored for the last square
  33. * Returns:  true - if it is a valid square,  false - otherwise
  34. *****************************************************************************/
  35. int LastSquare::isValidSquare (int newrow, int newcol)
  36. {
  37.    /*******************************************************************
  38.    ** This condition implies that this is the first square selected.
  39.    *******************************************************************/
  40.    if (row == 0)  return TRUE;
  41.  
  42.    if(newrow == row)
  43.    {
  44.       if (newcol == col-1 || newcol == col+1)
  45.          return TRUE;
  46.    }
  47.    if(newrow == row+1)
  48.    {
  49.       if (newcol == col || newcol == col-1 || newcol == col+1)
  50.          return TRUE;
  51.    }
  52.    if(newrow == row-1)
  53.    {
  54.       if (newcol == col || newcol == col-1 || newcol == col+1)
  55.          return TRUE;
  56.    }
  57.    return FALSE;
  58. }
  59.  
  60.  
  61. /*****************************************************************************
  62. * Function: setSquare
  63. * Parms:    row and column of square to check
  64. * Purpose:  will store the values for current square so we can perform
  65. *           adjacency checking later on
  66. * Returns:  nothing
  67. *****************************************************************************/
  68. void LastSquare::setSquare (int x, int y)
  69. {
  70.    row = x;  col = y;
  71. }
  72.  
  73. /*****************************************************************************
  74. * Function: reSetSquare
  75. * Parms:    none
  76. * Purpose:  initialize our values to zero
  77. * Returns:  nothing
  78. *****************************************************************************/
  79. void LastSquare::reSetSquare ()
  80. {
  81.    row = 0;  col = 0;
  82. }
  83.